package com.share.lottery.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.share.lottery.R;
import com.share.lottery.model.CaiboRmdBean;

public class CommendRunedAdapter extends BaseAdapter {
	private BitmapUtils bitmapUtils;
	private List<CaiboRmdBean> userList = new ArrayList<CaiboRmdBean>();
	private  Context context;
	public CommendRunedAdapter(Context context) {
		this.context = context;
		if (bitmapUtils == null) {
			bitmapUtils = new BitmapUtils(context);
		}
	}
	public int getCount() {

		return userList.size();
	}


	public CaiboRmdBean getItem(int arg0) {

		return userList.get(arg0);
	}


	public long getItemId(int arg0) {

		return arg0;
	}


	public View getView(int position, View convertView, ViewGroup arg2) {
		CaiboRmdBean caiboRmdBean = userList.get(position);
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_runed_zj, null);
			viewHolder = new ViewHolder();
			viewHolder.imgKind = (ImageView) convertView.findViewById(R.id.img_kind);
			viewHolder.tvKind = (TextView) convertView.findViewById(R.id.tv_kind);
			viewHolder.tvCurrent = (TextView) convertView.findViewById(R.id.tv_current_qh);
			viewHolder.tvGz = (TextView) convertView.findViewById(R.id.tv_gz);
			viewHolder.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
			viewHolder.imgUserHead = (ImageView) convertView.findViewById(R.id.img_head);
			viewHolder.tvUserName = (TextView) convertView.findViewById(R.id.tv_user_name);
			viewHolder.imgTag = (ImageView) convertView.findViewById(R.id.img_tag);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
			viewHolder.tvTime.setText(caiboRmdBean.getPublishTime());
			viewHolder.tvKind.setText(caiboRmdBean.getLotteryName());
			viewHolder.tvUserName.setText(caiboRmdBean.getUserName());
			viewHolder.tvCurrent.setText(caiboRmdBean.getContent());
			bitmapUtils.display(viewHolder.imgKind, caiboRmdBean.getLotteryImg());
			bitmapUtils.display(viewHolder.imgUserHead, caiboRmdBean.getUserImg());
			if ("1".equals(caiboRmdBean.getStatus())) {
				viewHolder.imgTag.setImageResource(R.drawable.huise);
				
			}else if ("2".equals(caiboRmdBean.getStatus())) {
				viewHolder.imgTag.setImageResource(R.drawable.hongse);
			}
			
		return convertView;
	}
	class ViewHolder {
		TextView tvTime;//时间
		ImageView imgKind;//
		TextView tvKind;//彩票种类
		TextView tvCurrent;//当前期号
		TextView tvGz;//请关注
		ImageView imgUserHead;//用户用户头像
		TextView tvUserName;//用户名
		ImageView imgTag;//成功或失败的标记


	}

	/**
	 * 添加数据
	 * 
	 * @param rows
	 */
	public void addDatas(List<CaiboRmdBean> rows) {
	
		userList.addAll(rows);

		notifyDataSetChanged();
	}

	/**
	 * 清空数据
	 */
	public void clearDatas() {
	
		userList.clear();
		notifyDataSetChanged();
	}

}
